<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateShippingAddressesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shipping_addresses', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('wechat_user_id')->unsigned()->notNull();
            $table->string('receiver_name', 255)->collate('utf8mb4_unicode_ci')->notNull();
            $table->string('receiver_phone', 255)->collate('utf8mb4_unicode_ci')->notNull();
            $table->string('receiver_address', 255)->collate('utf8mb4_unicode_ci')->notNull();
            $table->tinyInteger('is_default')->notNull()->default(0);
            $table->timestamps();

            // 添加外键约束
            $table->foreign('wechat_user_id')->references('id')->on('wechat_users')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('shipping_addresses');
    }
}